<?xml version="1.0"?>

<f:view
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets"
>
	<h:head>
		<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript" ></script>
	</h:head>
	<h:body>
		<h:form id="ads-form">  
			
			<p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" globalOnly="true"/>
			
			<BR/>
			<p:dataTable id="results" value="#{topAdsBean.advertisings}" var="row" emptyMessage="No result"
					paginator="true" rows="10" paginatorPosition="bottom"
					paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}  {CurrentPageReport}"
					>
				
				<p:column headerText="Manufacturer">
					<h:outputText value="#{topAdsBean.getManufacturerString(row)}" />
				</p:column>
				<p:column headerText="Model">
					
						<h:outputText value="#{topAdsBean.getModelString(row)}" />
					
				</p:column>
				<p:column headerText="Location">
					<p:commandLink update=":location-form" actionListener="#{topAdsBean.setSelectedLocation(row.location)}">
						<h:outputText value="#{row.location}" />
					</p:commandLink>
				</p:column>
				<p:column headerText="Details">
					<h:outputText value="#{row.carDescription}" />
				</p:column>
				<p:column headerText="User name">
					<p:commandLink rendered="#{topAdsBean.isUserLogedIn()}"
									update=":email-form" actionListener="#{topAdsBean.setSelectedUserId(row.userId)}">
						
						<h:outputText value="#{row.userName}" />
					</p:commandLink>
					<h:outputText rendered="#{!topAdsBean.isUserLogedIn()}" value="#{row.userName}" />
				</p:column>
				
			</p:dataTable>
			
		</h:form>
		
		<h:form id="email-form">  
			<p:dialog header="Send email" id="email-dialog" widgetVar="emailDlg">
				<p:panelGrid id="email-grid">
					<p:row>
						<p:column><h:outputText value="Subject: " /></p:column>
						<p:column>
							<p:inputText id="subject" required="true" value="#{topAdsBean.subject}" 
											 requiredMessage="Required field" styleClass="input-width"/>
							<p:message for="subject" display="text"/>
						</p:column>
					</p:row>
					<p:row>
						<p:column><h:outputText value="Message: " /></p:column>
						<p:column>
							<p:inputTextarea id="message" rows="10" value="#{topAdsBean.message}" styleClass="input-width"/>  
						</p:column>
					</p:row>
				    <p:row>
				    	<p:column colspan="2">
							<p:commandButton value="Send" actionListener="#{topAdsBean.sendMessage()}"/>
							<p:commandButton value="Cancle" type="button" onclick="emailDlg.hide()"/>
						</p:column>
			     	</p:row> 
				</p:panelGrid>
			</p:dialog>
		</h:form>
		
		<h:form id="location-form">
		
			<p:dialog id="map" widgetVar="gmapDialog" header="Location" modal="true" resizable="false">
				<h:outputLabel rendered="#{!topAdsBean.isGoogleMapRendered()}" value="Can not find location"/>
				<p:gmap rendered="#{topAdsBean.isGoogleMapRendered()}" center="#{topAdsBean.cordinate.getLat().toString()}, #{topAdsBean.cordinate.getLng().toString()}"
					zoom="13" type="ROADMAP" model="#{googleCalendarBean.advancedModel}" style="width:600px;height:400px">
					
			       
				</p:gmap>  
			</p:dialog>
		
		</h:form>
		 
		
	</h:body>
</f:view>